package com.tgy.leetcode;

/**
 * @Author: tgy
 * @Date: 12/30/20 10:56 AM
 */
public class _11_盛最多水的容器 {

    public int maxArea(int[] height) {

        if (height == null || height.length <= 1) {

            return 0;
        }

        int max = 0;

        int left = 0, right = height.length - 1;

        int leftCur = 0;
        int rightCur = 0;

        while (left < right) {


            if (height[left] <= leftCur) {

                left++;
                continue;
            }

            if (height[right] <= rightCur) {

                right--;
                continue;
            }

            int water = (right - left) * Math.min(height[left], height[right]);
            max = Math.max(max,water);

            if (height[left] <= height[right]) {

                leftCur = height[left];
                left++;
            }else {
                rightCur = height[right];
                right--;
            }

        }

        return max;
    }
}
